//蓝牙设备
var blue = function(){
	this.canvas = document.getElementById("canvas_blue");
	this.ctx = this.canvas.getContext("2d");
	this.drawwificount = 3; //wifi的个数
	this.drawwifiLasttime = 0; //wifi刷新间隔
	this.drawcircleLasttime = 0; //原点间隔时间
	this.drawcircleStatus = false; //切换颜色
}
blue.prototype.init=function(){
	
}

blue.prototype.draw=function(){
	this.ctx.clearRect(0, 0, this.width, this.height);
	this.drawRects(this.ctx);
	this.drawWifi(this.ctx);
	this.drawcircles(this.ctx);
}


//绘画外面的
blue.prototype.drawRects = function(ctx) {

	ctx.save();
	ctx.beginPath();
	ctx.shadowOffsetX = 0; //阴影x偏移
	ctx.shadowOffsetY = 0; //阴影y偏移
	ctx.shadowBlur = 15; //阴影强度
	ctx.shadowColor = 'rgba(200, 200, 200, 0.5)'; //模糊的阴影颜色
	ctx.fillStyle = "#1ec0ff99";
	ctx.strokeStyle = "#1ec0ff99";
	ctx.lineJoin = "round"; //圆角
	ctx.lineWidth = 3; //圆角大小
	// this.roundFillRect(ctx,0, 0, this.width, this.height,0);
	ctx.rect(0, 0, this.width, this.height);
	ctx.fill();
	ctx.stroke();
	ctx.restore();
}


// 绘制信号
blue.prototype.drawWifi = function(ctx) {

	// 	this.ctx.save();
	// 	this.ctx.beginPath();
	// 	this.ctx.arc(this.w_center,this.h_center,30,1.3*Math.PI,1.7*Math.PI);
	// 	this.ctx.stroke();
	// 	this.ctx.beginPath();
	// 	this.ctx.arc(this.w_center,this.h_center,20,1.3*Math.PI,1.7*Math.PI);
	// 	this.ctx.stroke();
	// 	this.ctx.beginPath();
	// 	this.ctx.arc(this.w_center,this.h_center,10,1.3*Math.PI,1.7*Math.PI);
	// 	this.ctx.stroke();
	// 	this.ctx.restore();
	// return;
	if (vue.isscanData) {
		this.drawwifiLasttime += deltaTime;
		if (this.drawwifiLasttime > vue.readCard) {
			this.drawwificount = (this.drawwificount + 1) % 3;
			this.drawwifiLasttime = 0;
		}
	} else {
		this.drawwificount = -1;
	}
	ctx.save();
	ctx.lineCap = "round";
	ctx.lineWidth = 1;
	ctx.strokeStyle = '#ffffff99';
	let startHeight = Math.floor(this.h_center / 4);
	for (var i = 0; i <= this.drawwificount; i++) {
		ctx.beginPath();

		// this.ctx.strokeStyle = i==0?'rgb(0,0,0,1)':(i==1?'rgb(0,0,0,0.7)':'rgb(0,0,0,0.5)');
		ctx.arc(this.w_center, this.h_center, startHeight + (i * 8), 1.3 * Math.PI, 1.7 * Math.PI);
		ctx.stroke();
	}
	ctx.restore();
}


//绘制下面的点

blue.prototype.drawcircles = function(ctx) {
	if (vue.isscanData) {
		this.drawcircleLasttime += deltaTime;
		if (this.drawcircleLasttime > vue.readCard) {
			this.drawcircleStatus = !this.drawcircleStatus;
			this.drawcircleLasttime = 0;
		}
	} else {
		this.drawcircleStatus = false;
	}

	let size = 4;
	let width = this.w_center;
	let height = this.h_center;
	let circleD_w = width; //宽
	let circleD_h = height; //高
	let circleD_x = this.w_center - (width / 2); //左标点
	let circleD_y = this.h_center + 5; //左标点

	let circle_jiange_w = circleD_w / size; //横向间隔
	let circle_jiange_h = circleD_h / size; //纵向间隔

	ctx.save();
	for (var i = 0; i <= size; i++) {
		for (var j = 0; j <= size; j++) {
			 ctx.beginPath();
			ctx.fillStyle = this.drawcircleStatus ? 'rgba(0, 0, 0, 0.4)' : 'rgba(0, 0, 0, 0.2)';
			ctx.arc((circleD_x + (i * circle_jiange_w)), (circleD_y + (j * circle_jiange_h)), 0.5, 0, 2 * Math
				.PI);
			ctx.fill();
		}
	}
	ctx.restore();


}



blue.prototype.size=function(){
	this.canvasrect= this.canvas.getBoundingClientRect();
	let radi = window.devicePixelRatio;
	this.width = this.canvasrect.width;
	this.height = this.canvasrect.height;
	// this.height = this.canvasrect.width;
	// console.log("w h ",this.width,this.canvasrect.height);
	
	this.canvas.style.width = this.width+"px";
	this.canvas.style.height = this.height+"px";
	this.canvas.width = this.width*radi;
	this.canvas.height = this.height*radi;
	this.ctx.scale(radi,radi);
	this.w_center= this.width/2;
	this.h_center = this.height/2;
	
}